package com.bk.controller;

import com.bk.domain.User;
import com.bk.service.UserService;
import com.bk.utils.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    public Result login(@RequestBody User user, HttpServletRequest request, HttpServletResponse response) {
        return userService.login(user,request,response);
    }

    @PostMapping("register")
    public Result register(@Valid @RequestBody User user, HttpServletRequest request) {
        return userService.register(user,request);
    }

    @GetMapping("logout")
    public Result logout(HttpServletRequest request,HttpServletResponse response) {
        return userService.logout(request,response);
    }

    @GetMapping("/info/{id}")
    public Result getUserInfo(@Valid @NotNull @PathVariable Long id, HttpServletRequest request) {
        return userService.getUserInfo(id,request);
    }

    @PutMapping
    public Result updateUserInfo(HttpServletRequest request, @RequestBody User user) {
        return userService.updateUserInfo(request,user);
    }

    @PostMapping("/ids")
    public Result getByIds(List<Integer> ids, HttpServletRequest request) {
        return userService.getByIds(ids, request);
    }

}
